from fuzzywuzzy import fuzz, process
import re

def custom_preprocessor(text):
    # 转换为小写
    text = text.lower()
    # 移除非字母数字字符
    text = re.sub(r'[^a-z0-9\s]', '', text)
    # 替换常见缩写
    replacements = {
        'inc': '',
        'llc': '',
        'corp': '',
        'ltd': ''
    }
    for k, v in replacements.items():
        text = text.replace(k, v)
    return text.strip()

# 使用自定义预处理
company_names = ["Microsoft Inc.", "Apple Corp", "Google LLC", "Amazon.com"]
query = "microsoft incorporated"

best_match = process.extractOne(
    query,
    company_names,
    processor=custom_preprocessor,
    scorer=fuzz.token_set_ratio
)

print(f"最佳匹配: {best_match}")